home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / biblio / bibtex / utils / bibextract / citetags.awk < prev    next >
Text File  |  1992-10-29  |  5KB  |  100 lines

  1. ### ====================================================================
  2. ###  @Awk-file{
  3. ###     author          = "Nelson H. F. Beebe",
  4. ###     version         = "1.02",
  5. ###     date            = "30 October 1992",
  6. ###     time            = "19:41:24 MST",
  7. ###     filename        = "citetags.awk",
  8. ###     address         = "Center for Scientific Computing
  9. ###                        Department of Mathematics
  10. ###                        University of Utah
  11. ###                        Salt Lake City, UT 84112
  12. ###                        USA",
  13. ###     telephone       = "+1 801 581 5254",
  14. ###     FAX             = "+1 801 581 4148",
  15. ###     checksum        = "49521 99 428 4617",
  16. ###     email           = "beebe@math.utah.edu (Internet)",
  17. ###     codetable       = "ISO/ASCII",
  18. ###     keywords        = "BibTeX, bibliography",
  19. ###     supported       = "yes",
  20. ###     docstring       = "*********************************************
  21. ###                        This code is hereby placed in the PUBLIC
  22. ###                        DOMAIN and may be redistributed without any
  23. ###                        restrictions.
  24. ###                        *********************************************
  25. ###
  26. ###                        Read a LaTeX file, or an .aux file, and
  27. ###                        extract the citation tags, outputting them
  28. ###                        one per line on stdout.
  29. ###
  30. ###                        The companion program, citefind.awk, can be
  31. ###                        used to extract the complete BibTeX entries
  32. ###                        for those tags from a bibliography file.
  33. ###                        This is useful when a small bibtex file
  34. ###                        must be prepared from large citation
  35. ###                        databases.
  36. ###
  37. ###                        Usage:
  38. ###                             nawk -f citetags.awk foo.ltx | sort > temp.tags
  39. ###                             nawk -f citefind.awk temp.tags bibfile(s) \
  40. ###                                   >newbibfile
  41. ###                             rm temp.tags
  42. ###
  43. ###                        The sort step is optional; citetags will
  44. ###                        not output duplicate tags, but they will be
  45. ###                        in random order.
  46. ###
  47. ###                        This program should normally be run via
  48. ###                        the separate citetags shell script.
  49. ###
  50. ###                        The checksum field above contains a CRC-16
  51. ###                        checksum as the first value, followed by the
  52. ###                        equivalent of the standard UNIX wc (word
  53. ###                        count) utility output of lines, words, and
  54. ###                        characters.  This is produced by Robert
  55. ###                        Solovay's checksum utility.",
  56. ###  }
  57. ### ====================================================================
  58.  
  59. ### Edit history (reverse chronological order):
  60. ### [21-Oct-1992]       1.01    Update for public distribution.
  61. ### [12-Apr-1989]       1.00    Original version.
  62.  
  63. /(\\cit(e|ation)|\\bibcite)/ {
  64.                     for (;;)    # loop over possible multiple \cite{} commands
  65.                     {
  66.                         $0 = substr($0,index($0,"\\cit"));
  67.                         comment_start = index($0,"%");
  68.                         if (comment_start > 0)
  69.                             $0 = substr($0,1,comment_start-1);
  70.                         line = substr($0,index($0,"{")+1);
  71.                         for (;;)
  72.                         {
  73.                             k = index(line,"}");
  74.                             if (k > 0)
  75.                                 break;
  76.                             getline;
  77.                             comment_start = index($0,"%");
  78.                             if (comment_start > 0)
  79.                                 $0 = substr($0,1,comment_start-1);
  80.                             line = line $0;
  81.                         }
  82.                         gsub(/[ \t]/,"",line);  # remove white space
  83.                         templine = line;
  84.                         line = substr(templine,1,k-1);
  85.                         # We now have a comma-separated tag word list
  86.                         split(line,taglist,",");
  87.                         for (n in taglist)
  88.                             tagtable[m++] = taglist[n];
  89.                         $0 = substr(templine,k);
  90.                         if ($0 !~ /\\cite/)
  91.                             break;              # no more \cite{} commands
  92.                     }
  93.                 }
  94.  
  95. # Now print the (unsorted) list of unique tags.
  96. END     {
  97.     for (n in tagtable)
  98.         print tagtable[n];
  99.     }
  100.